package com.yixin.hospital.common;

import com.yixin.hospital.enums.ResponseCodeEnum;
import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class ApiResult<T> {
    private int code;
    private String msg;
    private T data;

    public ApiResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ApiResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static <T> ApiResult<T> success(T data){
        return new ApiResult<>(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(), data);
    }

    public static <T> ApiResult<T> success(){
        return new ApiResult<>(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg());
    }

    public static <T> ApiResult<T> error(){
        return new ApiResult<>(ResponseCodeEnum.INTERNAL_SERVER_ERROR.getCode(), ResponseCodeEnum.INTERNAL_SERVER_ERROR.getMsg());
    }

    public static <T> ApiResult<T> error(String msg){
        return new ApiResult<>(ResponseCodeEnum.INTERNAL_SERVER_ERROR.getCode(), msg);
    }

    public static <T> ApiResult<T> error(int code, String msg){
        return new ApiResult<>(code, msg);
    }

    public static <T> ApiResult<T> error(ResponseCodeEnum res){
        return new ApiResult<>(res.getCode(), res.getMsg());
    }
}

